﻿using BuildDatabase.Repository;
using Ducu.BLL.Entity;
using Ducu.GLB.Story;
using Global.Core.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Story = Ducu.GLB.Global.Story;

namespace BuildDatabase.Factory
{
    internal static class PlanFactory
    {
        internal static void Create()
        {
            #region Yezi

            PlanRepository.Yezi_VOA = create(Plans.Yezi_English_VOA);
            PlanRepository.Yezi_VOA.Vower = UserRepository.Yezi;
            PlanRepository.Yezi_VOA.KeyWords = new List<Keyword>
            {
                KeywordRepository.VOA,
                KeywordRepository.English
            };

            SystemTime.SetDateTime(BaseDateTime.Point.AddDays(2));

            join(PlanRepository.Yezi_VOA, UserRepository.Abu);
            join(PlanRepository.Yezi_VOA, UserRepository.LuoMu);

            SystemTime.ResetDateTime();

            PlanRepository.Yezi_CATII = create(Plans.Yezi_Exam_CATII);
            PlanRepository.Yezi_CATII.Vower = UserRepository.Yezi;
            PlanRepository.Yezi_CATII.KeyWords = new List<Keyword>
            {
                KeywordRepository.CATTI,
                KeywordRepository.English,
                KeywordRepository.Exam
            };

            SystemTime.SetDateTime(BaseDateTime.Point.AddDays(3).AddHours(1));

            join(PlanRepository.Yezi_CATII, UserRepository.Abu);
          
            SystemTime.ResetDateTime();

            PlanRepository.Yezi_BBC = create(Plans.Yezi_English_BBC);
            PlanRepository.Yezi_BBC.Vower = UserRepository.Yezi;
            PlanRepository.Yezi_BBC.KeyWords = new List<Keyword>
            {
                KeywordRepository.English
            };

            PlanRepository.Yezi_Swim = create(Plans.Yezi_Exercise_Swim);
            PlanRepository.Yezi_Swim.Vower = UserRepository.Yezi;
            PlanRepository.Yezi_Swim.KeyWords = new List<Keyword>
            {
                KeywordRepository.Exercise
            };

            PlanRepository.Yezi_Run = create(Plans.Yezi_Exercise_Run);
            PlanRepository.Yezi_Run.Vower = UserRepository.Yezi;
            PlanRepository.Yezi_Run.KeyWords = new List<Keyword>
            {
                KeywordRepository.Exercise
            };

            PlanRepository.Yezi_Zheteng = create(Plans.Yezi_Writing);
            PlanRepository.Yezi_Zheteng.Vower = UserRepository.Yezi;
            PlanRepository.Yezi_Zheteng.KeyWords = new List<Keyword>
            {
                KeywordRepository.Writing
            };

            SystemTime.SetDateTime(BaseDateTime.Point.AddDays(5).AddMinutes(23));

            join(PlanRepository.Yezi_Zheteng, UserRepository.LuoMu);

            SystemTime.ResetDateTime();

            #endregion

            #region Abu

            PlanRepository.Abu_Exam = create(Plans.Abu_Exam_Account);
            PlanRepository.Abu_Exam.Vower = UserRepository.Abu;
            PlanRepository.Abu_Exam.KeyWords = new List<Keyword>
            {
                KeywordRepository.English,
                KeywordRepository.CATTI
            };

            #endregion

            #region Luomu

            PlanRepository.Luomu_Reading = create(Plans.LuoMu_Reading);
            PlanRepository.Luomu_Reading.Vower = UserRepository.LuoMu;
            join(PlanRepository.Luomu_Reading, UserRepository.Abu);

            #endregion

        }

        private static Plan create(Plan plan)
        {
            NHProvider.session.Save(plan);
            return plan;
        }

        private static void join(Plan plan, User user)
        {
            plan.JoinedBy(user);
        }
    }
}
